package com.zone.service.service.impl;

import java.util.List;
import com.zone.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zone.service.mapper.GunSecurityMapper;
import com.zone.service.domain.GunSecurity;
import com.zone.service.service.IGunSecurityService;
import com.zone.service.mapper.EmployeesMapper;
import com.zone.service.domain.Employees;

/**
 * 保安员证信息Service业务层处理
 * 
 * @author zone
 * @date 2025-11-06
 */
@Service
public class GunSecurityServiceImpl implements IGunSecurityService 
{
    @Autowired
    private GunSecurityMapper gunSecurityMapper;

    @Autowired
    private EmployeesMapper employeesMapper;

    /**
     * 查询保安员证信息
     * 
     * @param id 保安员证信息主键
     * @return 保安员证信息
     */
    @Override
    public GunSecurity selectGunSecurityById(Long id)
    {
        return gunSecurityMapper.selectGunSecurityById(id);
    }

    /**
     * 查询保安员证信息列表
     * 
     * @param gunSecurity 保安员证信息
     * @return 保安员证信息
     */
    @Override
    public List<GunSecurity> selectGunSecurityList(GunSecurity gunSecurity)
    {
        return gunSecurityMapper.selectGunSecurityList(gunSecurity);
    }

    @Override
    public List<GunSecurity> selectQuitSecurityList(GunSecurity query)
    {
        return gunSecurityMapper.selectQuitSecurityList(query);
    }

    /**
     * 新增保安员证信息
     * 
     * @param gunSecurity 保安员证信息
     * @return 结果
     */
    @Override
    public int insertGunSecurity(GunSecurity gunSecurity)
    {
        // 根据 employeeId 查员工
        if (gunSecurity.getEmployeeId() != null) {
            Employees emp = employeesMapper.selectEmployeesById(gunSecurity.getEmployeeId());
            if (emp != null && emp.getDepartmentId() != null) {
                gunSecurity.setDepartmentId(emp.getDepartmentId());
            }
        }

        gunSecurity.setCreateTime(DateUtils.getNowDate());
        return gunSecurityMapper.insertGunSecurity(gunSecurity);
    }

    /**
     * 修改保安员证信息
     * 
     * @param gunSecurity 保安员证信息
     * @return 结果
     */
    @Override
    public int updateGunSecurity(GunSecurity gunSecurity)
    {
        gunSecurity.setUpdateTime(DateUtils.getNowDate());
        return gunSecurityMapper.updateGunSecurity(gunSecurity);
    }

    /**
     * 批量删除保安员证信息
     * 
     * @param ids 需要删除的保安员证信息主键
     * @return 结果
     */
    @Override
    public int deleteGunSecurityByIds(Long[] ids)
    {
        return gunSecurityMapper.deleteGunSecurityByIds(ids);
    }

    /**
     * 删除保安员证信息信息
     * 
     * @param id 保安员证信息主键
     * @return 结果
     */
    @Override
    public int deleteGunSecurityById(Long id)
    {
        return gunSecurityMapper.deleteGunSecurityById(id);
    }
}
